define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'vppz/home_service_orders/index' + location.search,
                    //add_url: 'vppz/order/add',
                    //edit_url: 'vppz/order/edit',
                    //del_url: 'vppz/order/del',
                    multi_url: 'vppz/order/multi',
                    import_url: 'vppz/order/import',
                    table: 'vppz_home_service_orders',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                //fixedColumns: true,
                //fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),searchable:false},
						{field: 'order_no', title: '订单号', operate: 'LIKE'},
						{field: 'user.avatar', title: '用户', operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image,searchable:false},
						{field: 'user.nickname', title: '用户昵称', operate: 'LIKE'},
						{field: 'contect_name', title: '联系人', operate: 'LIKE'},
						{field: 'contect_phone', title: '联系电话', operate: 'LIKE'},
                        {field: 'patient_name', title: '客户姓名', operate: 'LIKE'},
                        {field: 'patient_sex', title: '客户性别'},
                        {field: 'patient_age', title: '客户年龄',searchable:false},
						{field: 'service_address', title: '客户地址', operate: 'LIKE'},
                        {field: 'scheduled_time', title: '预约时间', operate: 'LIKE'},

                        {field: 'price', title: __('Price'), operate:'BETWEEN',visible: false,searchable:false},
						{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime,visible: false},

						{field: 'status', title: __('Status'), searchList: {"pending":__('Status pending'),"confirmed":__('Status confirmed'),"completed":__('Status completed')}, formatter: Table.api.formatter.status,custom:{'pending':'warning','confirmed':'info','completed':'success'}},//"0":__('Status 0'),


						{field: 'medical_staff.avatar', title: '医护人员头像', operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image,searchable:false},
                        {field: 'medical_staff.name', title: '医护人员名称', operate: 'LIKE'},
						{field: 'community.name', title: '社区医院', operate: 'LIKE'},

                        //{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
